﻿@model IList<Topic>
@if (Model.Count > 0)
{
	<ul class="itemsHeader">
		<li class="name">@T("Title")</li>
		<li class="replies">@T("Replies")</li>
		<li class="views">@T("Views")</li>
		<li class="lastPost">@T("Last post")</li>
	</ul>
	<ul class="items">
		@foreach (Topic topic in Model)
		{
		<li class="@((topic.IsSticky ? "sticky " : "") + (topic.ReadAccessRole >= UserRole.Moderator ? "moderatorOnly" : ""))">

			<h3 class="name">
                @if (topic.UnreadMessagesCount > 0)
                {
                    string iconFile = topic.IsClosed ? "/contents/topic_unread_closed.gif" : "/contents/topic_unread.gif";
                    <img border="0" class="readIcon"
                        src="@Url.Content("~/Content/templates/" + ViewBag.Template.Name + iconFile)" 
                        alt="@S("{0} unread messages", topic.UnreadMessagesCount)" />
                }
                else
                {
                    string iconFile = topic.IsClosed ? "/contents/topic_read_closed.gif" : "/contents/topic_read.gif";
                    <img border="0" class="readIcon"
                        src="@Url.Content("~/Content/templates/" + ViewBag.Template.Name + iconFile)" 
                        alt="@S("No unread messages")" />
                }
                @Html.ActionLink(topic.Title, "Detail", "Topics", new { name = topic.ShortName, id = topic.Id, page = 1 }, new { @class = "itemTitle" })
				<span class="label">@T("by")</span>
				<span class="user">@Html.ActionLink(topic.User.UserName, "Detail", "Users", new { id = topic.User.Id }, null) </span>
				<span class="separator">- </span>
				<span class="date">@Html.Date(topic.Date)</span>
			</h3>
			<div class="replies">@(topic.Replies != 1 ? T("{0} <span class=\"label\">replies</span>", topic.Replies) : T("1 <span class=\"label\">reply</span>"))</div>
			<div class="separator">/ </div>
			<div class="views">@(topic.Views != 1 ? T("{0} <span class=\"label\">views</span>", topic.Views) : T("1 <span class=\"label\">view</span>"))</div>
			<div class="lastPost">
				@if (topic.LastMessage != null)
                {
					<span class="label">@T("Last post")</span>
					<span class="label2">@T("by")</span>
					<span class="user">@Html.ActionLink(topic.LastMessage.User.UserName, "Detail", "Users", new { id = topic.LastMessage.User.Id }, null) </span>
					<span class="separator">- </span>
					<span class="date">
						<a href="@(Url.Action("Detail", "Topics", new { name = topic.ShortName, id = topic.Id, page = Pager.CalculatePageNumber(Config.UI.MessagesPerPage, topic.LastMessage.Id) }))#msg@(topic.LastMessage.Id)">
                        @Html.Date(topic.LastMessage.Date)
						</a>
					</span>
                }
                else
                {
					<span class="nomsg">@T("No posts")</span>
                }
			</div>
		</li>
        }
	</ul>
}